package com.test.demo.service.impl;

import com.test.demo.dao.AccountDao;
import com.test.demo.model.Account;
import com.test.demo.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    private AccountDao accountDao;

    @Override
    public List<Account> getAccounts() {
        return accountDao.findAll();
    }

    @Override
    public Account getAccountById(int id) {
        //springboot如果是低版本可以直接使用  return accountDao.findOne(id);
        return accountDao.findById(id).orElse(null);
    }

    @Override
    public String updateAccount(Account account) {
        Account account1= accountDao.saveAndFlush(account);
        return account1.toString();
    }
}
